// pages/enrolldata/detail.js

const util = require('../../utils/util.js');
const apiUrl = require('../../utils/apiUrl.js');
var http = require('../../utils/httpHelper.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0,
    loadinghidden: true,
    detail: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    var id = options.id;
    if (id) {
      that.setData({
        id: id
      });
    } else {
      wx.showModal({
        title: '加载失败！',
        success: function (res) {
          if (res.confirm) {
            wx.navigateBack();
          }
        }
      })
      return;
    }

    // 显示 loading
    that.setData({
      loadinghidden: false
    });

    that.loadData();
  },
  loadData: function () {
    var that = this;
    var parameter = {};
    parameter['id'] = that.data.id;
    http.ApiGet(apiUrl.UrlEnrollDataShow, parameter, function (res) {
      wx.stopPullDownRefresh() //停止下拉刷新
      if (res.code == 1) {
        var detail = res.data;

        util.removeNull(detail);

        that.setData({
          loadinghidden: true,
          detail: detail,
        });
      } else {
        wx.showModal({
          title: res.msg
        });
      }
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.loadData();
  },
  copyTap: function(e) {
    var val = e.currentTarget.dataset.val;
    if (val.length > 0) {
      wx.setClipboardData({
        data: val,
        success: function(res) {
          console.log(res);
        }
      });
    }
  },
  signTap: function () {
    var that = this;
    http.ApiPost(apiUrl.UrlEnrollDataSign, {
      "id": that.data.id
    }, function (res) {
      if (res.code == 1) {
        that.loadData();
      } else {
        wx.showModal({
          title: res.msg
        });
      }
    });
  },
  imageTap: function (e) {
    var val = e.currentTarget.dataset.val;
    if (val.length > 0) {
      wx.previewImage({
        current: val, // 当前显示图片的http链接  
        urls: [val] // 需要预览的图片http链接列表  
      })
    }
  }
})